/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.ieslaferreria.creditsintesis.logicgame.actions;

import com.jme.math.Vector3f;
import edu.ieslaferreria.creditsintesis.logicgame.MobilObject;

/**
 *
 * @author josep
 */
public class ForwardAction implements Action<ProcessMobileObjectStateEvent>{
    //temporary vector for the rotation
    private static final Vector3f tempVa = new Vector3f();

    /**
     * The vehicle to accelerate is supplied during construction.
     * @param node the vehicle to speed up.
     */
    public ForwardAction() {}

    /**
     * the action calls the vehicle's accelerate command which adjusts its velocity. It
     * then translates the vehicle based on this new velocity value.
     */
    public boolean performAction(ProcessMobileObjectStateEvent evt) {
        MobilObject node = (MobilObject) evt.getObjectWithStates();
        Vector3f loc = node.getLocalTranslation();
        System.out.print("Old Loc: (" +loc.x + ", " + loc.y +  ", " + loc.y + ")");
        loc.addLocal(node.getLocalRotation().getRotationColumn(2, tempVa)
                .multLocal(node.getLinealVelocity() * evt.getTime()));
        System.out.println(" New Loc: (" +loc.x + ", " + loc.y +  ", " + loc.y + ")");
        System.out.println("Increment: " + node.getLinealVelocity() * evt.getTime());
        node.setLocalTranslation(loc);
        return true;
    }
}
